// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './styles/index.scss'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from '@/store/Store.js'
import ECharts from 'vue-echarts'
Vue.component('chart', ECharts)
Vue.use(ElementUI)
Vue.config.productionTip = false
// 添加路由守卫---使用 router.beforeEach 注册一个全局前置守卫
// to: Route: 即将要进入的目标 路由对象
// from: Route: 当前导航正要离开的路由
// next(): 进行管道中的下一个钩子。
// 路由守卫是自动触发的
router.beforeEach((to, from, next) => {
  // console.log(to)
  // 根据用户的路由跳转，进行判断，如果没登录要先登录
  // 获取token值
  var token = localStorage.getItem('mytoken')
  if (token) {
    next()
  } else {
    if (to.path === '/login') {
      next()
    } else {
      next({path: '/login'})
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  // 注入store
  store,
  components: { App },
  template: '<App/>'
})
